gpt4 book ai didi

javascript - execCommand() 将 url 替换为 ../

转载 作者:行者123 更新时间:2023-11-28 10:03:36 26 4
gpt4 key购买 nike

我在我的所见即所得中插入了一个图像网址,但 Firefox 不知何故用 ../替换了我的网址

string += "<img src='"+encodeURI(domain)+"/"+file_name+"' id='"+filename+"'>";
console.log(string);

控制台记录以下内容:

<img src='http://www.testing.com/web_graph.gif' id='web_graph.gif'>

然后使用

document
.getElementById("texto_a_editar")
.contentWindow
.document
.execCommand('inserthtml', false, string);

我明白了:

<img src="../web_graph.gif" id="web_graph.gif">

我应该怎么做才能获得完整的网址?

最佳答案

var completeURI = location.href,
completeURIi = location.href.lastNidexOf("/"),
img = document.getElementById("web_graphic.gif").getAttribute("src");
img = img.substr(img.lastIndexOf("/") + 1);
completeURI = completeURI.substr(0, completeURI.lastIndexOf("/") + 1) + img;

关于javascript - execCommand() 将 url 替换为 ../,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8679318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com