Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将location.href URL转换为锚定链接_Javascript_Iphone_Html_Uiwebview - Fatal编程技术网

Javascript 将location.href URL转换为锚定链接

Javascript 将location.href URL转换为锚定链接,javascript,iphone,html,uiwebview,Javascript,Iphone,Html,Uiwebview,存在任何JavaScript或Objective-C方法来转换位置。href=MyURL为 我有超过200个location.href URL无法使用UIWebViewNavigationTypeLinkClicked:-S 谢谢大家能帮助我 <a href="http://www.myurl.com" id="myAnchor"></a> <script type="text/javascript"> document.ge

存在任何JavaScript或Objective-C方法来转换位置。href=MyURL为

我有超过200个location.href URL无法使用UIWebViewNavigationTypeLinkClicked:-S

谢谢大家能帮助我

    <a href="http://www.myurl.com" id="myAnchor"></a>

    <script type="text/javascript">
        document.getElementById("myAnchor").setAttribute("href", window.location.href);
        var loc = document.getElementById("myAnchor").getAttribute("href");
        var t = document.createTextNode(loc);
        document.getElementById("myAnchor").appendChild(t);
    </script>
这里有一种方法:document.getElementById获取对锚定的ID属性的引用。setAttribute的第二个参数window.location.href获取对当前窗口中url的引用,并将锚点中的href attibute设置为该参数,但是如果在代码中声明了大量location.hrefs,然后将它们作为变量存储在第一行之前,然后在我声明loc的同一行引用该变量。变量loc声明了一个变量,该变量存储对您刚才在前一行中声明的新创建的href属性的引用。然后我声明一个变量t,它在DOM中创建一个文本节点,并将前一行中的href作为该变量的值。最后,我使用document.getElementById再次获取myAnchor并将前一行中的文本节点附加到它。现在我们可以在链接中看到url了

        //Also, use a for loop to run this action 200 times and correct all of the   hrefs       on your page.
        <script type="text/javascript">
           for (var i=0;i<200;i++){
              //run document.getElementById() and .setAttribute, .createTextNode, etc. here
            }
        </script>
工作小提琴:


我不建议使用document.write;正如另一个人的帖子中提到的,由于这会导致页面以某种方式工作,DOM并不打算写入序列化文本。特别是如果你需要纠正200个错误。请看这篇文章

我认为您应该澄清您的问题:您是否有一个HTML文本,其中的链接表示为location.href text,并且您希望将基本文本翻译成标记?请更详细地描述该问题,以便我们能够帮助您我希望我的Javascriptevent{location.href=http://... }可以像锚定链接一样被浏览器读取。这可能吗?让我们看看:你有这个事件,基本上加载那个URL,对吗?您希望显示指向该页面的链接,而不是加载该页面?在这种情况下,您可以将函数重写为。。。{document.write;}。。。应该会显示链接