Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to simulate such clicks without controlling web browsers to do the job. I don't know much about javascript and actually don't know where to start.
Any ideas?
Althoug I have no use it, I think that maybe twill is what you need:
twill: a simple scripting language for Web browsing
Have a look at this too:
Testing Web Applications with Python and Twill
You can use iMacros in combination with Python...
This isn't the most direct solution as it requires you to write an iMacros script to do that actual clicking, and then load the page and call the script from Python.
Refereces:
iMacros CLICK command
iMacros wiki
I recommend you take a look at Selenium.
If you had control over the link (like adding an ID attribute) you could use javascript to simulate the click
var link = document.getElementById['yourLinksIdAttrbuteValue'];
link.click();
or you could use jQuery selectors as an easy way to better target the link without altering it...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script>
$(function(){ $("a[href^='javascript']:contains('text')").click() });
</script>
With that code it'll load the JQuery library from google's server, wait for the dom to load, then execute the click.
for more info on jQuery selectors check out http://api.jquery.com/category/selectors/
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been working now for a while on the javascript process and can't really figure out on how to do this. I know how to basically tell javascript to set a certain value for a specific ID. But my Problem here is:
I'd like to write javascript to read out information (Server based, but that I'll do by myself ofc.) set it as var and then write it into text. It should look like this in the end:
Before writing (Without Javascript):
<h1 id="name" class="normal">Welcome, %Name%! What do you wish to do?</h1>
After writing (With Javascript):
<h1 id="name" class="normal">Welcome, John Connor! What do you wish to do?</h1>
So basically what I thought of is, that JS reads out information from server, then finds the h1 ID, searches in that text the %Name% value, and replaces it with the found name.
Please help me out here.Thanks!
Best Regards
Kodaigan
If using jQuery:
$('#name').html(function(index, html){
return html.replace('%Name%', yourVariable);
});
Pure javascript:
document.getElementById('name').innerHTML = document.getElementById('name').innerHTML.replace('%Name%','John');
This will replace a given string inside your h1 element.
If you have many paramaters, is better to use one of js lib's with templating.I prefere to use underscore.
http://underscorejs.org/#template. Also you can use if statements in youe template
How to use if statements in underscore.js templates?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am currently working on a website which requires one page on the website to open others using the post method through a script, i.e., without direct user input. I have attempted to use the JQuery post method, but can get no results.
In order to test the code I have attempted to run the post method in its simplest form, with only a URI, attempting to open various web pages, but so far nothing has happened.
I have confirmed that the JQuery script is running (hence the 'alert' function) so the problem must be with the post method. I have researched this problem exhaustively both on stackoverflow and on other sites, even copying and attempting the run numerous samples of code, but have found nothing helpful. I have not under any circumstances observed either the get or post method functioning at all.
When I first had this problem I was on a Linux machine; I have attempted to repeat my experiments on Windows without success. I have attached my full test code, both html and javascript, below.
<!DOCTYPE html>
<html>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("The Button was Clicked.")
$.post("http://www.spacex.com/");
});
});
</script>
<body>
<h2>Web Page </h2>
<p>Click the Button to Open the Website </p>
<button>Button</button>
</body>
</html>
You need to either read the response into a callback function.
$.post("ajax/test.html", function(data) {
$(".result").html(data);
});
Or if you want to call the page directly, setup a regular form in your page and use jquery to submit it.
$("button").click(function() {
$("#targetform").submit();
});
Or even simpler still, just submit the form in the old fashioned way with a form action and submit button, no JQuery required.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've been told loading jQuery at the end of a page increases performance for mobile.
I don't believe this, however open for an explanation.
Regardless, is there any way to get jQuery calls at the beginning of the page to load only after jQuery has been loaded? I know of timeout work around but they seem inconsistent.
The reason why you get "better" performance is that the page will be parsed before it reaches JavaScript at the end of the document, and once a section is parsed, rendering can begin. By loading JavaScript at the end of the document, you let the basic hard-coded layout in your HTML and CSS appear before you add functionality with JavaScript. This gives the user the illusion of "faster loading time" for your page.
The caveat here is any JavaScript you want to use that will call on external libraries must occur after the libraries' script tags. This is not an issue if you have packed all of your code together into its own file, but it will cause trouble for inline scripts you have strewn about the page.
This is part of why such behavior is discouraged in production applications, the rest having to do with the ability to maximize compression of the script content with gzip and so on.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to do a pre-loading for a website:
I want to create a loading page/image/etc. to show before the actual
page is loaded.
Nice would be something like a spinner/loading-bar
The pre-loader shell vanish when the actual page is fully loaded
How can i achieve this?
You should check if all elements of webpage are loaded.
You can use JQuery, for example:
$(document).ready( function() {
// something here
})
From jQuery documentation:
The .ready() method is generally incompatible with the attribute. If load must be used, either do not use .ready()
or use jQuery's .load() method to attach load event handlers to the
window or to more specific items, like images.
I don't know your programming skills, but if you are aware of javascript and jQuery you could easily try this tutorial:
http://avexdesigns.com/create-a-jquery-preloader/
The Plugin you will find here: http://www.inwebson.com/jquery/jpreloader-a-preloading-screen-to-preload-images/
and all about jquery is found here: http://jquery.com
You can have a progressbar in ur webpage before loading ur actual content.
Refer the link below.
http://tutorialzine.com/2013/09/quick-tip-progress-bar/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm going crazy! :)
I need a way to add a closing </div> before another element. But everything I try the </div> gets filtered out. The problem is, that this might be the only solution for me.
So please, please have a look to this and maybe you're able to give me a hint:
I'm building a bootstrap based template for LimeSurvey, a online survey tool. Their templates are completely done with tables and I try to find another way and to get it mobile friendly.
The template is separated into different files. For my issue this is:
-> Startpage
-> Navigator
-> Endpage
Normally it loads always a "Surveypage" between Startpage and Navigator. But there is an option which automatically puts all question directly under the startpage and therefore into my header. So in this case I need another '' or another way to close the header first.
So there's a
<div class="jumbotron">
and I have to close it before the element
<table id="ls-table" ... >
I already tried many JavaScript examples I've been able to find around the web. But none makes the job.
Thanks a lot!
Philipp
There are only two ways to manipulate a web page using JavaScript.
The DOM, or document object model.
Via string-manipulation of the HTML.
Most web browsers will NOT allow you to do #2 directly on an already-loaded or loading document. At best, you could find a situation wherein you read the HTML of a <body> and then re-parse it. But doing so is an amazing amount of work for very little effort.
Look into the insertBefore method on the DOM, which will let you grab that <table id="ls_table" > element and move it from within that <div> to being a child of said <div>'s parent, immediately after the offending element.