简体   繁体   English

某些用户操作更改了链接href后,从Chrome到桌面的拖放链接无法创建正确的桌面快捷方式

[英]Drag&dropping link from Chrome to desktop does not create a correct desktop shortcut after the link href was changed by some user action

In my application I have a link to some other web page. 在我的应用程序中,我有一个指向其他网页的链接。 A user can drag that link to his desktop and create a shortcut for that page. 用户可以将该链接拖动到他的桌面上并为该页面创建快捷方式。 The thing is, that after some things happen at runtime, I want THIS SAME element to point to a different web page. 事实是,在运行时发生了一些事情之后,我希望THIS SAME元素指向另一个网页。 Changing the href of the element works as it should: after it is changed the link can be clicked and the correct new page is opened. 更改元素的href可以正常工作:更改元素后,可以单击链接并打开正确的新页面。 But, the drag&drop to desktop functionality does not work fine with Chrome: 但是,拖放到桌面功能不适用于Chrome:

Case 1: Default browser is IE, the new link is dropped to desktop, double click on the desktop shortcut opens it in IE -> the correct new page is opened. 情况1:默认浏览器为IE,新链接被放置到桌面,双击桌面快捷方式在IE中打开它->打开正确的新页面。

Case 2(the problem): Default browser is Chrome, the new link is dropped to desktop, double click on the desktop shortcut opens it in Chrome BUT it is the old page, like the url was never changed.. 情况2(问题):默认浏览器是Chrome,新链接被删除到桌面,双击桌面快捷方式在Chrome浏览器中将其打开,但它是旧页面,就像url从未更改一样。

I tried a simple test where the href changes on button click and it happens there too: 我尝试了一个简单的测试,其中href在单击按钮时发生了变化,它也发生在这里:

<input type="button" id="button" value="Change url" />
<span>
    <a id="theLink" href="http://www.w3schools.com">link</a>
</span>

var onClick = function() {
     $("#theLink").attr("href", "http://www.w3schools.com/jquery");
};

$('#button').click(onClick);

Can be tried here: http://jsfiddle.net/cealyx/pazdj9kd/4/ 可以在这里尝试: http : //jsfiddle.net/cealyx/pazdj9kd/4/

It works fine with IE. 它可以与IE正常工作。 Doesn't work when default browser is Chrome or Mozilla. 当默认浏览器为Chrome或Mozilla时不起作用。 OS: Windows 8.1 Used jQuery 2.0.3. 操作系统:Windows 8.1 Used jQuery 2.0.3。

When I open the properties of the shortcut: In the "Web Document" tab the URL is not the correct new one. 当我打开快捷方式的属性时:在“ Web Document”选项卡中,URL不是正确的新URL。 However in "Details tab" the URL is correct, so it managed to update to some point..... 但是,在“详细信息选项卡”中,URL是正确的,因此它设法进行了更新。

Have someone run into this issue before and are there solutions? 有人遇到过这个问题吗,有解决方案吗? Some explanation why this is happening should be nice too. 为什么会发生这种情况的一些解释也应该很好。 Thanks 谢谢

I found the link text must also be changed for it to be recognized as a different link with a different URL, when dragged to the desktop. 我发现链接文本也必须更改,以便在拖动到桌面时被识别为具有不同URL的其他链接。 As even having 2 links with the same text and switching between one being hidden and one being visible, strangely enough, did not work. 甚至有2个链接都具有相同的文本,并且在隐藏一个链接和显示一个链接之间切换时,奇怪的是,该链接不起作用。 But if you change text slightly in addition to the URL , I am finding that to work in Chrome 45. 但是,如果您除了URL之外还稍微更改了文本 ,我发现它可以在Chrome 45中使用。

<a id='mylink' href='http://google.com'>Google</a>

$('#mylink').prop('href', 'http://booble.com').html('Google~') //Works
$('#mylink').prop('href', 'http://booble.com') //Does not work
$('#mylink').prop('href', 'http://booble.com').html('Google') //Does not work

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM