Chrome extension popup page link doesn't work

☆樱花仙子☆ 提交于 2021-02-07 18:37:45

问题


I was creating a Chrome extension for fun, but i got a problem with my popup page. I used jQuery load() function to load a part of existed page, let's say: http://aaa.com:

<div id="aaa-news">
$(document).ready(function(){
     $("#ox-news").load("http://aaa/News/ .news_list");
});
</div>

Since the part of page i tried to load into popup.html contains some links, but seems href attributes of these links have been modified by Chrome whenever they are loaded in popup.html.So even if i used chrome.tabs.create.* API to open a new tab, it always showed me

No webpage was found for the web address: Chrome extension://phigdpgmolbpdcihdohfpbafibncbkhl/News/1 Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.

Anyone has idea? Appreciated for your help!


回答1:


To fix relative links you can use <base> tag. It is also useful to make all links inside popup to open in a tab by setting target="_blank" (otherwise links become non-clickable):

<base href="http://aaa/" />
<base target="_blank" />



回答2:


I had the same problem, and solved it by using the following chrome extension :

New Tab Redirect! 2.0

https://chrome.google.com/webstore/detail/icpgjfneehieebagbmdbhnlpiopdcmna

Click the original chrome pages "New Tab" button on the tab that appears the after installation of this extension.



来源:https://stackoverflow.com/questions/6851606/chrome-extension-popup-page-link-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!