1

我创建了一个小书签,将数据从我的站点加载到第三方站点上的对话框中。

  • 这是为了帮助第三方网站的用户使用手动完成时很乏味的功能。
  • 当从图像超链接拖动到 Chrome 和 Firefox 中的收藏夹/书签栏时,小书签可以工作
  • 但是,在 IE(9) 中,我只能通过更改一些数据来编辑超链接并将其放回原处,然后单击“确定”。内容不变

我在下面粘贴了我的脚本的通用版本

function loadScript(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (script.readyState) {
        script.onreadystatechange = function() {
            if (script.readyState == "loaded"
                    || script.readyState == "complete") {
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {
        script.onload = function() {
            callback();
        };
    }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}
if (typeof (runMyCode) == "undefined") {
    loadScript(
            "http://mysite/myscript.js",
            function() {
                runMyCode();
            });
} else {
    runMyCode();
}

如果我删除最后一个分号并保存书签,它可以工作:/

编辑:在下面添加了 html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>My tile</title>
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">        
</head>
<body>
<a href="javascript:function loadScript(url, callback) {    var script = document.createElement(&quot;script&quot;);    script.type = &quot;text/javascript&quot;;  if(script.readyState) {     script.onreadystatechange = function() {            if (script.readyState == &quot;loaded&quot;                 || script.readyState == &quot;complete&quot;) {     script.onreadystatechange = null;   callback();         }       };  } else {    script.onload = function() {            callback();     };  }   script.src = url;   document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script);}if (typeof(runMyCode) == &quot;undefined&quot;) {loadScript(&quot;http://mysite/myscript.js&quot;,function() {runMyCode();});} else{ runMyCode();}"
title="Drag me to your Bookmark and click me to check your remaining tiles in a game">
<img border="0" alt="My Alt Text" src="http://mysite/myimage" />
</a>

<br/>
<span>Drag the image above to your bookmarks toolbar<br/>and more text</span>
</body>
</html>
4

0 回答 0