Is it possible to integrate a javascript into a hyperlink? Or make it into some sort of batch script or whatnot, so when the page has loaded it calls the javascript which is a button on the page?
To explain it further:
We have this page:
http://work.acceptance.XXXX.com/XXXX_Raffle/Lists/Raffle/overview.aspx
The sharepoint page has a survey on it.
To get the "popup" window to show, so you can answer a question in the survey, you need to press a button which calls this script:
javascript:__doPostBack('ctl00$m$g_e999ab40_719f_42fb_bd61_d986f232bdd5$ctl01$ctl00$toolBarTbl$RptControls$ctl00$diidIONewItem','');
So, is it possible to somehow combine the page + the javascript, so all they have to do is press one link or alternatively, a hyperlink which goes to a file on a server which triggers all this, so they instantly get to the page + the javascript automatically pops so they dont have to press the button?
Keep in mind, when I say "hyperlink" I mean the kind of hyperlink you would see in an email. A simple link to a website or a server location.
I'm not very good at everything that has to do with programming and webdesign, but I do have access to the sharepoint, though I'd need serious guiding in how to add anything there other than simple webparts. It's SharePoint Server 2010.
Here is a picture of the button and what happens when you press it.
http://i.stack.imgur.com/gKCG5.jpg
Add an onload event to the page to get it to show the popup:
<script type="text/javascript">
window.onload = showPopup();
function showPopup() {
__doPostBack('ctl00$m$g_e999ab40_719f_42fb_bd61_d986f232bdd5$ctl01$ctl00$toolBarTbl$RptControls$ctl00$diidIONewItem','');
}
</script>
This needs to go on the page that you're linking to so that the link takes you to this page which then fires this onload. Put it before the closing tag on the page.
No. You cannot construct a URL that will load a document and then call some JavaScript.
You would have to modify the page you are linking to so it runs the JS automatically. It could look at the URL and run that function conditionally though (e.g. if (location.hash === '#foo') { ... }.)
Related
My website has button A. When I click it a pop up div appears with yes no option. I must click yes. So I write a script so that when I click button A, the yes option is automatically clicked. It goes like this
buttonA.onclick = function(){
document.getElementById('buttonYes').click()
};
I load this into Tampermonkey. When the page loads, the code work for the first time. After that the button goes back to their original behavior. The Javascript somehome only works once when the page is newly loaded. Can someone suggest a way to make the code works all the time in the page and I don't need to reload the page for it to work.
I was trying to make an application in SharePoint and wanted to make it so that if you click on a button, it redirects you to a page and when that page loads I wanted it to instantly redirect the user to another page. ( I couldn't get the button to just redirect to the page I wanted on click, so that's why I tried doing it this way. ) I did this using a jQuery / JavaScript script. I'm new to making scripts so I was just testing and I ended up making this script:
<script type="text/javascript">
$(document).ready(function(){
Redirect();
});
function Redirect(){
$(document).load("url");
}
</script>
My problem is now that whenever that page loads, it just loads a blank page. But I can't get to the edit screen because it instantly redirects me to a blank page. I tried turning off JavaScript in Google Chrome but even though I was able to load the page without redirecting, I wasn't able to get to the edit page because it's in a jQuery AJAX drop down menu which obviously also doesn't work if JavaScript is turned off.
I would appreciate any help
EDIT: When I say edit screen I mean the place where I can edit the script. To do that I have to press a button on the page, but I can't do that since the page instantly redirects to a blank page.
Use the webpart maintenance page which allows you to remove and manage web parts without visiting the page, the instructions are as below.
Lets say your page is example.com/sites/default.aspx add the query string ?contents=1 to the page it will take you to the manage web parts page you can remove the script editor web part from there.
The other way is to use SharePoint designer to remove the web part this will also help you achieve the same result.
I want to be able to toggle a javascript function that opens a certain tab on my page when the page loads. However I only want this function to run automatically when coming from another page.
For example:
Page A has the function that opens said tab, which is triggered when clicking on a button normally.
I want the user to click a button on page B and redirect to page A, where the function on page A automatically triggers.
However if the user reaches page A from anywhere but page B I do not want this function to trigger automatically.
This is the best way I can describe it, any help would be great. (I should also mention this is being done is ASP.NET MVC4)
You can use document.referrer. Something like this.
if (document.referrer === 'pageB') {
// trigger the function
}
I am trying to get this functionality going but am a bit uncertain and don't know how to approach it. I have a master page with a div called "masterDiv". 'masterDiv' makes a load() call and loads content of an external html page called "details.html" from it content div. This is how I am doing it:
$('#masterDiv').load('details.html #content');
content loads up as expected and the url address pops in as "http://www.xyz.com#details"
This is all good and working, but then I thought of those users who may not have JavaScript endabled. I figure I would just direct those users to 'details.html' page directly instead of having the "Master Page" load the content from "details.html" page. So now here is the issue, lets say if I send a user this link:
http://wwww.xyz.com#details
And if that user's browser doesn't have Javascript enabled then obviously JQuery cannot be invoked and therefore load() call will not be made and so on. how can I direct the user to "details.html" page directly, please?
Any insight would be wonderful
Thank you.
Your link probably looks like this :
<a id="myLink" href="#details">Link that the user clicks</a>
When the user clicks the link, jQuery load is called. Is that correct?
If so, you could instead have your link like this :
<a id="myLink" href="http://wwww.xyz.com/details.html">Link that the user clicks</a>
That way, when the page loads, the link will work for everyone (even those with javascript disabled). Then, when the page first loads :
$(document).ready(function() {
$('#myLink').attr('href', '#details');
});
will set the link to the way it was before. That way, only users with Javascript enabled will use the load version. The other ones will simply be redirected to details.html
If there is something I haven't understood correctly in the question let me know.
how can I direct the user to "details.html" page directly, please?
By making the link's href attribute "details.html". The way every link works by default.
Details
Every link on your site should be built this way. That is how the Internet is designed to work, and how it works best. You should only add functionality with JavaScript if you actually need to, you shouldn't be depending on it for something as fundamental as linking between pages.
I am currently making a temporary download page for website visitor.
The page includes a form, after the visitor fills the form up, the site will take them to the pdf download page.
In the download page, there are some pdf files download links (I am just using a tag.). However, i wanna make a onclick event to those links, once they have been clicked, the page will refresh automatically or redirect to other pages.
The File
I have tried the jquery way as well.
The File
<script>
$("#FileDownload").click(function(){
location.reload();
});
</script>
But all the them are not working. Do you masters have any good ideas about this, many thanks.
P.S. What if I wanna add a countdown after a file is being started download, and then do page reload when countdown finishes.
Looks like have asked several questions... Thanks a ton in advance.
This works:
http://jsbin.com/imikit/5
The timeout must be set to more than the response time of the server serving the file, otherwise the javascript won't fire. So set it to something high.
The File
$('#download').click(function() {
setTimeout(function() {
window.location = 'http://www.google.com/';
}, 1000);
});
Or
The File
$('#download').click(function() {
window.location = 'http://www.google.com/';
});
Most browsers will close the newly opened window once the download has initiated.
Lighttpd 2's mod_upload might be worth looking at. Unfortunately there's no stable version of Lighttpd 2 yet.
You could try sending a cookie along with the download, then detecting it with javascript. This will either be set after the headers are sent, or after the body is sent. (test it)
One thing you can do is open the download in a new window, then redirect the page.
The File
<script>
$("#FileDownload").click(function(e){
e.preventDefault();
window.open(this.href);
location.reload();
});
</script>
You have two options for the onClick parameter:
Add semicolons between each line that can have one
Write a function to do all your tasks an have the onClick method call that.
Someone else might be able to help with the jQuery side, but it would be similar, I would think.
All of these methods will fire as many events as you like.
For the countdown, try the setTimeout() function.
EDIT: After seeing comments, try Click Here. This will open the link in a popup window and reload the current one - you may need the setTimeout() for the reload so the link opens before the reload() event fires.
When you click on a link the default action is to follow it and adding onClick code doesn't change that.
Try:
onClick="windows.location.reload();return false;"
This will solve the first part.
As for the second part (counter/redirect on download finish) use this plugin http://johnculviner.com/post/2012/03/22/Ajax-like-feature-rich-file-downloads-with-jQuery-File-Download.aspx to download the file and use successCallback to redirect:
$.fileDownload('/file.pdf', {
successCallback: function () {
windows.location.reload();
}
});