-1

I have a page called Page1.html held at http://intranet/ with the contents:

<div id="username">my.username</div>.

I'd like to use jQuery to read this value into my Chrome Extension.

Currently I have hard coded text: document.getElementById("username").value="mcgurk" in my script.js of my Chrome Extension but I'd prefer to grab the value in the username element.


Potentially useful:

I'm not great with Javascript but I did follow this tutorial a little: http://www.dynamicdrive.com/forums/showthread.php?67448-document-getElementById-from-another-page which recommends something like this code:

<script type="text/javascript">
jQuery(function($){
    $('#result').load('Page2.html #intro');
});
</script>

Their example works great but I'd like to build the above into a Chrome Extension.

Can anyone provide assistance for this issue?

michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
  • 2
    Nah, that code snippet is pretty useless for the task. See [How to access the webpage DOM rather than the extension page DOM?](https://stackoverflow.com/q/4532236) for a condensed explanation with a small code example and many of existing answers for another approach: [extension content script popup messaging](https://www.google.com/#q=stackoverflow+extension+content+script+popup+messaging) for more examples. – wOxxOm Sep 12 '16 at 10:34

2 Answers2

1
$.ajax({
    url: 'https://intranet/index.php',
    success: function(html) {
        var nodes = $.parseHTML(html);
        var username = $("<div>").append(nodes).find("#username").text();
        $('#username').val(username);
    }
});
michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
1
$('#username').load('http://intranet/index.php',function() {
alert( "username was loaded successfully." );
});

Try to get the values using the load function in jquery

Parthasarathy
  • 308
  • 2
  • 10