Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using HTML and javaScript .. I'm trying to build a chrome extension , which will display some info from the website in the popup

I need to get the page source of http://met.guc.edu.eg in the context of my web page and use it to get some of the "li" tags and do some work on them ( RegEx )

for example display the courses taken by student in web page -- By taking them from the http://met.guc.edu.eg .. and display them in a nice way in a pop up

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
962 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since there is no true answer to this yet, I will post the method I use - I do not know if it's the best way - but it works.

The reason XHR may not be the best idea is because it's not always going to give you the exact source of a certain tab - this way will.

content.js


chrome.extension.onRequest.addListener(function(request, sender, callback)
{
    if (request.action == 'getSource')
    {
        callback(document.documentElement.outerHTML);
    }
});

background.html


chrome.tabs.sendRequest(tab.id, {action : 'getSource'}, function(source) {
    console.log(source);
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...